/**
 * GroupsDao.java
 *
 * Copyright (c) 2009 prjmanager All Rights Reserved.
 *
 * This source file may not be copied, modified or redistributed,
 * in whole or in part, in any form or for any reason, without the express
 * written consent of prjmanager .
 **/

package ro.prjmanager.dao;

import org.hibernate.SQLQuery;
import ro.prjmanager.core.dao.GenericDAO;
import ro.prjmanager.model.Groups;
import ro.prjmanager.model.Projects;

import java.util.List;

/**
 * This interface provides custom method declaration for Groups
 * entity and has a default implementation in the same package :
 * GroupsDAOImpl
 * @author Viorel Tacliciu
 * @version 0.0.1
 */

public class GroupsDao extends GenericDAO<Groups,  java.lang.Integer> {
    @Override
    @SuppressWarnings("unchecked")
    public List<Groups> findAll() {
        Integer idProject=((Projects)getUserSession().getProject()).getId();
        SQLQuery query=getSession().createSQLQuery("select * from groups a where a.fk_project="+idProject);
        query.addEntity(getPersistentClass()) ;
        return query.list();
    }


    @Override
    @SuppressWarnings("unchecked")
    public List<Groups> listPagFilter(int startPage, int resPerPage, String sqlFilter) {
        StringBuilder sql=new StringBuilder("select c.* from groups c where c.fk_project=")
                .append(((Projects)getUserSession().getProject()).getId());
        sql.append(" ");
        sql.append(sqlFilter.replace("where",""));

        SQLQuery sqlQuery=getSession().createSQLQuery(sql.toString());
        sqlQuery.setMaxResults(resPerPage);
        sqlQuery.setFirstResult(startPage);
        sqlQuery.addEntity(getPersistentClass());
        return sqlQuery.list();
    }

   
}
